package com.woniu.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.entity.WechatExceptions;
import com.woniu.entity.YaoExceptions;
import com.woniu.mapper.YaoExceptionsMapper;
import com.woniu.service.YaoExceptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author LXB
 * @Date 2024/1/16 21:01
 * @Description
 **/
@Service
public class YaoExceptionsServiceImpl extends ServiceImpl<YaoExceptionsMapper, YaoExceptions> implements YaoExceptionsService {

    @Autowired
    private YaoExceptionsMapper yaoExceptionsMapper;

    /**
     * 摇摇啦记录日志
     * @param jsonObject 返回数据
     * @param remark 备注
     * @param orderNumber 订单号
     */
    @Override
    public void yaoExceptionDispose(JSONObject jsonObject, String remark,String orderNumber) {
        YaoExceptions yaoExceptions = new YaoExceptions();
        yaoExceptions.setErrcode(jsonObject.getString("errcode"));
        yaoExceptions.setErrmsg(StrUtil.isNotBlank(jsonObject.getString("errmsg")) ? jsonObject.getString("errmsg") : "");
        yaoExceptions.setData(jsonObject.toJSONString());
        yaoExceptions.setRemark(remark);
        yaoExceptions.setOrderNumber(orderNumber);
        yaoExceptions.setCreateTime(DateUtil.date());
        yaoExceptions.setUpdateTime(DateUtil.date());
        yaoExceptionsMapper.insert(yaoExceptions);
    }
}
